﻿using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Entity;

namespace DAO
{
    public class ContactDAO
    {

        BMS_DatabaseEntities context = new BMS_DatabaseEntities();
        public List<ContactEntity> LoadContact(string companycode)
        {
         
            var query = from c in context.CONTACT_PERSON
                        where c.COMPANY_CODE == companycode
                        select new ContactEntity
                        {
                            CompanyCode=c.COMPANY_CODE,
                            CompanyName=c.COMPANY_NAME,
                            ContactPerson=c.CONTACT_PERSON1,
                            Email=c.EMAIL,
                            Tel=c.TEL,
                            Remark=c.REMARK,
                            //Birthday = (DateTime)c.BIRTHDAY,
                            Address=c.ADDRESS,
                        };

            return query.ToList<ContactEntity>();
        }

        public void AddContact(ContactEntity info)
        {
            var query = new CONTACT_PERSON
            {
                CONTACT_PERSON1 = info.ContactPerson,
                TEL = info.Tel,
                EMAIL = info.Email,
                ADDRESS = info.Address,
                REMARK = info.Remark,
            };
            context.CONTACT_PERSON.Add(query);
            context.SaveChanges();
        }
    }
}
